#include <vector>
#include "Evaluation.h"
#include "LOX.h"
using namespace std;

void LOX::Run( std::vector<Solution> &output, const Solution &solution_1, const Solution &solution_2 )
{
	int keep_job_num = Evaluation::GetJobNum() / 2 ,keep_job_start = Evaluation::GetJobNum() / 4 
		,keep_job_end = keep_job_start + keep_job_num - 1 ,x = 0;
	vector<int> solution(Evaluation::GetJobNum() , 0);
	for(int i = keep_job_start;i <= keep_job_end;i++){
		solution[i] = solution_1.getElementAt(i);
	}
	for(int i = 0;i < Evaluation::GetJobNum();i++){
		int j = keep_job_start ,y = solution_2.getElementAt(i);
		for(;j <= keep_job_end;j++){
			if(y == solution[j]){break;}
		}
		if(j > keep_job_end){
			solution[x] = y;
			x++;
			if(x == keep_job_start){x += keep_job_num;}
		}
	}
	output.push_back( Solution(solution) );
	for(int i = keep_job_start;i <= keep_job_end;i++){
		solution[i] = solution_2.getElementAt(i);
	}
	x = 0;
	for(int i = 0;i < Evaluation::GetJobNum();i++){
		int j = keep_job_start ,y = solution_1.getElementAt(i);
		for(;j <= keep_job_end;j++){
			if(y == solution[j]){break;}
		}
		if(j > keep_job_end){
			solution[x] = y;
			x++;
			if(x == keep_job_start){x += keep_job_num;}
		}
	}
	output.push_back( Solution(solution) );
}
